/**
 * 认为第一列为第一级Key，第一行为次级key
 * 
[
    ['ID', 'StagePrefabName']
    [1, 'stage_001']
    [2, 'stage_002']
    [3, 'stage_003']
]
-->
{
    1: {ID: 1, StagePrefabName: stage_001}
    2: {ID: 2, StagePrefabName: stage_002}
    3: {ID: 3, StagePrefabName: stage_003}
}
 **/

export function xlsxArrayToMap(data: Array<Array<any>>) {
    const keys = data[0];
    const obj = {};
    for (let i = 1; i < data.length; i++) {
        const row = data[i];
        const subObj = {};
        if (row[0] == null) continue;
        for (let j = 0; j < keys.length; j++) {
            const key = keys[j];
            if (!key.startsWith('#')) {
                if (row[j] != null) {
                    subObj[key] = row[j];
                }
            }
        }
        obj[row[0]] = subObj;
    }
    return obj;
}

export function xlsxArrayToMapEx(data: Array<Array<any>>) {
    const keys = data[0];
    const obj = {};
    let _subRect = null;
    for (let i = 1; i < data.length; i++) {
        const row = data[i];
        const subObj = {};
        if (row[0] == null) {
            _subRect['toIdx'] = i;
            continue;
        } else {
            _subRect = { fromIdx: i, toIdx: i };
        }
        for (let j = 0; j < keys.length; j++) {
            const key = keys[j];
            if (!key.startsWith('#')) {
                if (row[j] != null) {
                    subObj[key] = row[j];
                }
            }
        }
        subObj['_subRect'] = _subRect;
        obj[row[0]] = subObj;
    }
    obj['_data'] = data;
    return obj;
}


